import Vue from "vue"
import Vuex from "vuex"
import storage from "@/uni-sub-base/utils/storage.js"
import tabBarModule from "./modules/tab-bar"
import sunbathingBar from "./modules/sunbathing"

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        token: "",
        cartData: [],
        supplierCartData: [],
        tempCartData: [],
        isUp: "",
        isUpCartView: "",
        isUpOrderView: "",
        ismomentView: "",
        isUpRemarkView: "",
        isUpReturnOrderView: "",
        useAddress: null,
        themeColor: "",
        scrollviewtop: true,
        isWarehouseNameView: "",
        isProjectView: "",
		skipone:1,
		apiUrl:'',
        networkType: 'none', // 网络状态
    },
    mutations: {
        SET_NETWORK_TYPE(state, networkType) { //设置网络状态
			state.networkType = networkType || 'none';
		},
        SET_AUTH(state, token) {
            state.token = token
            storage.setCache("token", token)
        },
		SET_APIURL(state, apiUrl) {
		    state.apiUrl = apiUrl
		    storage.setCache("apiUrl", apiUrl)
		},
        SET_VIEWTOP(state, scrollviewtop) {
            state.scrollviewtop = scrollviewtop
        },
        CLEAR_AUTH(state) {
            state.token = ""
            storage.setCache("token", "")
        },
		SKIP_ADD(state){
			 state.skipone = 2
		},
		SKIP_RESET(state){
			 state.skipone = 1
		},
        SET_CART(state, cartData) {
            state.cartData = cartData
        },
        SET_SUPPLIER_CART(state, cartData) {
            //供应商购物车
            state.supplierCartData = cartData
        },
        SET_TEMP_CART(state, tempCartData) {
            state.tempCartData = tempCartData
        },
        UP_VIEW(state, isUp) {
            state.isUp = isUp
        },
        UP_CART_VIEW(state, isUpCartView) {
            state.isUpCartView = isUpCartView
        },
        UP_ORDER_VIEW(state, isUpOrderView) {
            state.isUpOrderView = isUpOrderView
        },
        UP_MOMENT_VIEW(state, ismomentView) {
            state.ismomentView = ismomentView
        },
        UP_REMARK_VIEW(state, isUpRemarkView) {
            state.isUpRemarkView = isUpRemarkView
        },
        UP_RETURN_ORDER_VIEW(state, isUpReturnOrderView) {
            state.isUpReturnOrderView = isUpReturnOrderView
        },
        SET_USE_ADDRESS(state, useAddress) {
            state.useAddress = useAddress
        },
        SET_THEME_COLOR(state, color) {
            state.themeColor = color
        },
        UP_WARE_VIEW(state, isWarehouseNameView) {
            state.isWarehouseNameView = isWarehouseNameView
        },
        UP_PROJECT_VIEW(state, isProjectView) {
            state.isProjectView = isProjectView
        },
    },
    getters: {
        getToken(state) {
            return state.token
        },
        getCartData(state) {
            return state.cartData
        },
        getSupplierCartData(state) {
            return state.supplierCartData
        },
        getTempCartData(state) {
            return state.tempCartData
        },
        getUpView(state) {
            return state.isUp
        },
        getUpCartView(state) {
            return state.isUpCartView
        },
        getUpOrderView(state) {
            return state.isUpOrderView
        },
        getMomentView(state) {
            return state.ismomentView
        },
        getUpRemarkView(state) {
            return state.isUpRemarkView
        },
        getUpReturnOrderView(state) {
            return state.isUpReturnOrderView
        },
        getUseAddress(state) {
            return state.useAddress
        },
        getThemeColor(state) {
            return state.themeColor
        },
        getWareView(state) {
            return state.isWarehouseNameView
        },
        getProjectView(state) {
            return state.isProjectView
        },
    },
    actions: {
        setCartData(data) {
            state.cartData = data
        },
        setSupplierCartData(data) {
            state.supplierCartData = data
        },
    },
    modules: {
        tabBar: tabBarModule,
        sunbathing: sunbathingBar,
    },
})

export default store
